package ru.spies.help;

import ru.spies.entities.ITableClass;

public class OperationsData {
	
	private int cnt=0;
	private String params[]=null;
	private ISetOperations operations[]=null;

	public OperationsData() {
		
	}
	
	public void addNewOperation(ISetOperations operation, String param){
		if (param==null) {
			MyLogger.getInstance().getLog().error(MyLogger.CANT_FIND_THIS_PARAM);
			return;
		}
		cnt++;
		String newParams[] = new String[cnt];
		params=(String[]) resizeArray(params, newParams, param);
		ISetOperations[] newOperations = new ISetOperations[cnt];
		operations = (ISetOperations[]) resizeArray(operations, newOperations, operation);
	}
	
	private Object[] resizeArray(Object old[],Object newObject[],Object newElement){
		if (old!=null){
			for (int i = 0; i < old.length; i++) {
				newObject[i]=old[i];
			}
		}	
		newObject[cnt-1]=newElement;
		return newObject;
	}
	
	public void doOperations(ITableClass tableObject){
		if (operations==null) return;
		for (int i = 0; i < operations.length; i++) {
			operations[i].doSet(tableObject, params[i]);
		}
	}

}
